package com.esiran.payadmin.util;

import java.util.Random;

public class NumUtilEx {
    public static  String makeRandomNum(int m){
        Random random = new Random();
        StringBuilder result = new StringBuilder();
        for (int i=0;i<m;i++){
            float c = random.nextFloat();
            int cc = (int) (c*10);
            result.append(cc);
        }
        return result.toString();
    }
    public static String makeRegularNum(){
        String now = CalendarUtilEx.simpleFormat("yyyyMMddHHmmss");
        String nowTimeMillis = String.valueOf(System.currentTimeMillis());
        String nowTimeMillisFix = nowTimeMillis.substring(nowTimeMillis.length()-5);
        String randomNum = makeRandomNum(5);
        return now.concat(nowTimeMillisFix).concat(randomNum);
    }
    public static Double parseDouble(Double d){
        return Math.floor(d*100)/100;
    }
    public static boolean checkMoneyFix(Double money){
        if (money == null){
            return false;
        }
        String ms = String.valueOf(money);
        String[] m = ms.split("[.]");
        int fix = Integer.parseInt(m[1]);
        return fix <= 9;
    }
    public static Long fixMoney2long(Double money){
        if (money == null){
            return null;
        }
        if (!checkMoneyFix(money)){
            return null;
        }
        Double fixed = money*100;
        return fixed.longValue();
    }
    public static Double fixMoney2double(Long money){
        if (money == null){
            return null;
        }
        return parseDouble(money/100d);
    }
}
